package com.xinxing.learning.datasource.controller;

import com.xinxing.learning.datasource.constants.DataSourceConstants;
import com.xinxing.learning.datasource.entity.TestUser;
import com.xinxing.learning.datasource.service.TestUserService;
import com.xinxing.learning.datasource.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class TestUserController {

    @Autowired
    private TestUserService testUserService;

    /**
     * 查询全部
     */
    @GetMapping("/listall")
    public Object listAll() {
        Map<String, Object> result = new HashMap<>();

        //默认master数据源查询
        List<TestUser> masterUser = testUserService.getMasterUser();
        result.put(DataSourceConstants.DS_KEY_MASTER, masterUser);
        //从slave数据源查询
        List<TestUser> slaveUser = testUserService.getSlaveUser();
        result.put(DataSourceConstants.DS_KEY_SLAVE, slaveUser);
        //返回数据
        return ResponseResult.success(result);
    }

}